package mud.controller;

import mud.entity.RatedItem;
import mud.support.RatedParser;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/bailu")
public class GenericController {
    private final RatedParser parser = new RatedParser();

    @GetMapping(path = "/p")
    public RatedItem parseUrl(
            @RequestParam(value = "url") String url
    ) {
        parser.connectUrl(url);
        RatedItem item = new RatedItem();
        item.setLabel(parser.getName());
        item.setDetail(parser.getEd2k());
        item.setAddition(url);
        return item;
    }
}
